﻿using System;
using System.Collections.Generic;
using System.IO; 
using System.Text;

namespace Parseq.Util
{
    public class String
    {
        public static Stream StringToStream(string s)
        {
            return StringToStream(s, Encoding.UTF8);
        }

        public static Stream StringToStream(string s, Encoding enc)
        {
            return new MemoryStream(enc.GetBytes(s));
        }

        public static long StringToLong(string s)
        {
            return Convert.ToInt64(s);
        }

        public static double StringToDouble(string s)
        {
            return Convert.ToDouble(s); 
        }

        public static string ArrayToString(Array ary)
        {
            return ArrayToString(ary, ",", "{", "}");
        }

        public static string ArrayToString(Array ary, string delim, string open, string close)
        {
            string[] output = new string[ary.Length];
            long i = 0;
            foreach (object o in ary)
            {
                if (o is Array)
                {
                    output[i] = ArrayToString((Array)o, delim, open, close);
                }
                else
                {
                    output[i] = o.ToString();
                }
                ++i;
            }
            return string.Format("{0}{1}{2}", open, string.Join(delim, output), close);
        }

        public static string ObjectCharsToString(object[] chars)
        {
            return ArrayToString(chars, "", "", ""); 
        }
        public static string CharsToString(char[] chars)
        {
            return new string(chars);
        }
    }
}
